<template>
  <div>
    <header class="flex" id="header">
      <template v-if="isShow">
        <i class="iconfont icon-return" @click="toHome"></i>
        <h1>所有分类页</h1>
        <i class="iconfont icon-search" @click="goToSearch"></i>
      </template>
      <template v-else>
        <div class="search_box">
          <form name="searchForm" id="searchForm_id">
            <input placeholder="请输入商品名称" name="keywords" type="text" id="keywordBox">

          </form>
          <i id="icon-search" class="iconfont icon-search"></i>
        </div>
        <i class="iconfont icon-close" @click="goToSearch"></i>
      </template>

    </header>

    <div class="clist total-clist">
      <ul v-for="(item,index) in firstMenuList" :key="index">
        <li class="crow level1">
          <div class="crow_row">
            <div class="crow_icon"> <img src="../../assets/img-detail/icon1.png"> </div>
            <div class="crow_title">
              <span>{{item.title}}</span>
            </div>
            <div class="crow_arrow upAndDown" @click="showClist(item.id)">
              <img :ref="'zxwx'+`${item.id}`+'down'" src="../../assets/img-detail/xia.png">
              <img style="display:none" :ref="'zxwx'+`${item.id}`+'up'" src="../../assets/img-detail/shang.png">
            </div>
            <!-- <div>&nbsp;</div> -->
          </div>
         
          <ul :ref="'zx'+`${item.id}`"  class="clist clist_sub clearfix" style="opacity: 1;display:none">
            <li class="crow">
              <div v-for="(it,i) in item.children" :key="i" class="crow_item crow_item_clear">
                <a>{{it.title}}</a>
              </div>
              <div class="crow_item">
                <a>全部商品</a>
              </div>
            </li>
          </ul>
        </li>

      </ul>
    </div>
  </div>
</template>
<script>
import { createNamespacedHelpers } from "vuex";
const { mapState, mapMutations, mapActions } = createNamespacedHelpers(
  "sliderNav"
);
export default {
  data() {
    return {
      isShow: true,
      isXia: true,
      isblock: "isblock",
      ishid: "ishid",
      firstMenuList: [],
    };
  },
  mounted() {
    this.getTypes().then(data => {
      this.firstMenuList = data;
    });
  },
  methods: {
    ...mapActions(["getTypes"]),
    goToSearch() {
      this.isShow = !this.isShow;
    },
    toHome() {
      this.$router.push("/");
    },
    showClist(id) {
    
     if(this.isXia){
       this.$refs['zx'+id][0].style="display:block"
       this.$refs['zxwx'+id+'up'][0].style="display:block"
       this.$refs['zxwx'+id+'down'][0].style="display:none"

        //  this.isXia  = !this.isXia
     }else{
       this.$refs['zx'+id][0].style="display:none"
       this.$refs['zxwx'+id+'up'][0].style="display:none"
       this.$refs['zxwx'+id+'down'][0].style="display:block"
     }
     this.isXia  = !this.isXia
     console.log(this.isXia )
    }
  }
};
</script>
<style scoped>
.isblock {
  display: block;
}
.ishid {
  display: none;
}
.clearfix:after {
  display: block;
  clear: both;
  content: "";
}
header {
  height: 48px;
  background: #ff3838;
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.flex {
  display: flex;
  align-items: center;
}
.icon-search,
.icon-return,
#header h1,
.icon-close {
  color: #fff;
}
#header h1 {
  font-size: 18px;
  font-weight: normal;
}
.icon-search {
  margin-right: 14px;
}
.icon-return {
  margin-left: 12px;
}

.icon-search,
.icon-return {
  display: inline-block;
  font-size: 26px;
}
.search_box {
  top: 0;
  margin: 0 10px;
}
.icon-close {
  font-size: 24px;
  margin-right: 10px;
}
#icon-search {
  color: #ccc;
  font-size: 20px;
}
.total-clist {
  margin-top: 48px;
}
.clist ul {
  width: 100%;
  background: #f4f4f4;
}
.crow {
  line-height: 72px;
  width: 100%;
  background: #f4f4f4;
  clear: both;
  height: 72px;
}
.crow_row {
  border-bottom: #d7d7d8 1px solid;
  line-height: 72px;
  width: 100%;
  height: 72px;
}
.crow_icon {
  line-height: 115px;
  margin: 0px 10px;
  width: 57px;
  float: left;
  height: 57px;
}
.crow_icon img {
  width: 57px;
  height: 57px;
}
.crow_title {
  line-height: 72px;
  float: left;
  margin-left: 5px;
}
.crow_title span {
  font-size: 16px;
  height: 72px;
}
.crow_arrow {
  float: right;
  margin-right: 20px;
}
.crow_arrow img {
  width: 16px;
}
.clist_sub {
  border-bottom: 1px solid #d7d7d8;
}

.crow_item_clear {
  border-left-width: 0px;
  box-shadow: 0px 0 0px #fff;
  -webkit-box-shadow: 0px 0 0px #fff;
}
.crow_item {
  text-align: center;
  line-height: 32px;
  margin: 20px auto;
  width: 32%;
  font-family: "华文细黑";
  background: #f4f4f4;
  float: left;
  height: 32px;
  color: #585858;
  font-size: 14px;
  border-left: #d7d7d7 1px solid;
}
.crow_item a {
  margin: 0px 5px;
  text-overflow: clip;
  white-space: nowrap;
  color: #000;
}
 .upAndDown img{
  line-height: 72px;
 }
</style>